package cn.tedu.hospital.admin.server.freebased.dao.persist.repository.impl;

import cn.tedu.hospital.admin.server.freebased.dao.persist.mapper.FreeBasedDetailMapper;
import cn.tedu.hospital.admin.server.freebased.dao.persist.repository.IFreeBasedDetailRepository;
import cn.tedu.hospital.admin.server.freebased.pojo.entity.FreeBasedDetail;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

/**
 * 处理患者详情数据的存储库实现类
 *
 * @author java@tedu.cn
 * @version 1.0
 */
@Slf4j
@Repository
public class FreeBasedDetailRepositoryImpl implements IFreeBasedDetailRepository {

    @Autowired
    private FreeBasedDetailMapper freeBasedDetailMapper;

    public FreeBasedDetailRepositoryImpl() {
        log.info("创建存储库对象：ArticleDetailRepositoryImpl");
    }

    @Override
    public int insert(FreeBasedDetail freeBasedDetail) {
        log.debug("开始执行【插入患者详情】的数据访问，参数：{}", freeBasedDetail);
        return freeBasedDetailMapper.insert(freeBasedDetail);
    }

    @Override
    public int deleteByArticle(Long articleId) {
        log.debug("开始执行【根据患者ID删除患者详情数据】的数据访问，参数：{}", articleId);
        QueryWrapper<FreeBasedDetail> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("article_id", articleId);
        return freeBasedDetailMapper.delete(queryWrapper);
    }

    @Override
    public int updateByArticle(FreeBasedDetail freeBasedDetail) {
        log.debug("开始执行【更新患者详情】的数据访问，参数：{}", freeBasedDetail);
        QueryWrapper<FreeBasedDetail> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("patientId", freeBasedDetail.getFreebasedId());
        return freeBasedDetailMapper.update(freeBasedDetail, queryWrapper);
    }

}